import { UserModel, ArticleModel } from "@/database";
import type { User } from "~/type";

/**
 * 文章列表
 * @url /api/v1/article/getArticleList
 * @method GET
 */
export default defineEventHandler(async (event) => {
    const { page = 1, size = 12 } = getQuery<{ page: number, size: number }>(event)
    const list = ArticleModel.slice((page - 1) * size, page * size).map(item => {
        return {
            ...item,
            user: UserModel.find(userItem => userItem.id === item.user_id) as User //确保本地数据一定存在,否则前端会报错
        }
    })

    const total = ArticleModel.length
    const seo_title = 'seo文章列表'
    const seo_description = 'seo文章列表'
    const seo_keywords = 'seo文章列表'
    return successApi('请求成功', {
        list,
        total,
        seo_title,
        seo_description,
        seo_keywords
    })
})